/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jsysacc.asistencia.model.dao.ds;

import com.cerd.util.BaseSP01.JUtilBaseSP01;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ResourceBundle;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.postgresql.ds.PGPoolingDataSource;

/**
 *
 * @author Carlos
 */
public class PoolConexiones {

    private final ResourceBundle rb = ResourceBundle.getBundle("com.jsysacc.asistencia.model.dao.ds.cnx");
    PGPoolingDataSource source = null;
    private String schema;
    private static PoolConexiones instancia = new PoolConexiones();

    public static PoolConexiones getInstancia() {
        return instancia;
    }

    public PoolConexiones() {
        JUtilBaseSP01 JUB = JUtilBaseSP01.JUtilBaseSP01;
        StandardPBEStringEncryptor s = new StandardPBEStringEncryptor();
        s.setPassword(JUB.getKeyEncryt());
        String pass_in = rb.getString("PASS");
        String pass_out = "";
        try {
            pass_out = s.decrypt(pass_in);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        source = new PGPoolingDataSource();
        source.setDataSourceName("JSysAcc");
        source.setServerName(rb.getString("IP"));
        source.setDatabaseName(rb.getString("DB"));
        source.setUser(rb.getString("USER"));
        source.setPassword(pass_out);
        source.setMaxConnections(5);
        this.setSchema(rb.getString("SCHEMA"));
    }

    public Connection getSource() throws SQLException {
        return source.getConnection();
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

}
